'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:TaskTaskreportCtrl
 * @description
 * # TaskTaskreportCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('TaskTaskreportCtrl', function(DataService, DataByPage, openApi, $location, $routeParams) {
        var athoritylist = [{
            value: "查日报",
            className: "icon_check",
            target: "choosedaily"
        }, {
            value: "查周报",
            className: "icon_check",
            target: "chooseweekly"
        }];
        this.switchmenu = function(target) {
            $location.path("task/" + target)
        };
        this.reporttype = $routeParams.reporttype //默认显示日报
        this.switchreport = function() {
            $location.path('task/taskreport/' + this.reporttype)
            $location.replace();
        }
        this.initdata = function() {
                if (this.reporttype == 1) {
                    this.reportList = new DataByPage(openApi.getworklog);
                } else if (this.reporttype == 2) {
                    this.reportList = new DataByPage(openApi.getWeeklyApp);
                }
            }
            // this.switchreport()
        this.initdata();
        this.goDetail = function(item) {
            console.log(item)
            var param = {}
            param.pkId = item.pkId;
            if (this.reporttype == 1) {
                $location.path("task/dailydetail/" + item.pkId)
            } else if (this.reporttype == 2) {
                $location.path("task/weeklydetail/" + item.pkId)
            }
        };
        DataService.getData(openApi.worktaskpublic).then(function(data) {
            this.isManager = data
            this.menulist = [{
                value: "写日报",
                className: "icon_edit",
                target: "newdaily"
            }, {
                value: "写周报",
                className: "icon_edit",
                target: "newweekly"
            }];
            if (this.isManager != 0) {
                this.menulist = this.menulist.concat(athoritylist)
            }
        }.bind(this))
    });
